<template>
    <div class="page has-navbar index" v-nav="{title:titleName, showBackButton: true,showMenuButton: true, onMenuButtonClick: toggleSidebar}">
        <div class="page-content">
            <div v-if="showFirstBg" class="firstBg" @click="showFirstBg=false"></div>
            <router-view :storeId="storeId"></router-view>
        </div>
    

        <div class="sidebar-container" :class="{close:!sidebarOpened}" @click="toggleSidebar">
            <div class="sidebar" @click.stop="">
                <div class="topLogo"></div>
                <scroll class="sideBarTemplate">
                    <router-link @click.native="toggleSidebar()" tag="div" class="sideBarItem" v-for="(item,idx) in sidebarData" :to="'/index/'+item.routeName" :active-class="'active'" :key="idx">
                        <i :class="item.iconClass"></i>
                        <span v-text="item.name"></span>
                    </router-link>
                </scroll>
                <div class="bottom">
                    <div class="bottomItem" @click="$router.push('/store')">
                        <i class="iconfont icon-qihuan"></i>
                        <span>切换店铺</span>
                    </div>
                    <div class="bottomItem" @click="logOut()">
                        <i class="iconfont icon-guanbi"></i>
                        <span>退出</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            sidebarOpened: false,
            storeData: '',
            sidebarData: [
                
                {
                    name:"销售统计",
                    iconClass: "iconfont icon-xiaoshoumaolitongjibaobiao",
                    son:[],
                    routeName:`saleStatic`,
                },
                {
                    name:"机位在线数据",
                    iconClass: "iconfont icon-navicon-jytj",
                    son:[],
                    routeName:`siteData`,
                },
                // {
                //     name:"交易趋势",
                //     iconClass: "iconfont icon-xiaoshoumaolitongjibaobiao",
                //     son:[],
                //     routeName:`salesHot`,
                // },
                // {
                //     name:"会员统计",
                //     iconClass: "iconfont icon-vip",
                //     son:[],
                //     routeName:`vipStatistics`,
                // },
                
                // {
                //     name:"店铺报表",
                //     iconClass: "iconfont icon-ccgl-baobiao-8",
                //     son:[],
                //     routeName:`statement`,
                // },
                // {
                //     name:"排单机",
                //     iconClass: "iconfont icon-navicon-jytj",
                //     son:[],
                //     routeName:'bigScreenGoods',
                // },
                {
                    name:"库存详情",
                    iconClass: "iconfont icon-kucun",
                    son:[],
                    routeName:'stockDetail',
                },
                {
                    name:"仓库出入库",
                    iconClass: "iconfont icon-kucun",
                    son:[],
                    routeName:'stockUpDown',
                },
                {
                    name:"吧台上下架",
                    iconClass: "iconfont icon-kucun",
                    son:[],
                    routeName:'barUpDown',
                },
                {
                    name:"交接班记录",
                    iconClass: "iconfont icon-shujufenxi",
                    son:[],
                    routeName:`changeWork`,
                },
                {
                    name:"电子对账单",
                    iconClass: "iconfont icon-dianzibaobiaoxitong",
                    son:[],
                    routeName:`electronBill`,
                },
                {
                    name:"对账单",
                    iconClass: "iconfont icon-navicon-jytj",
                    son:[],
                    routeName:`storeBill`,
                },
                {
                    name:"营业趋势",
                    iconClass: "iconfont icon-navicon-jytj",
                    son:[],
                    routeName:`rateData`,
                },
                
                {
                    name:"同期日报表(周)",
                    iconClass: "iconfont icon-navicon-jytj",
                    son:[],
                    routeName:`ringReport`,
                },
                // {
                //     name:"经营日报",
                //     iconClass: "iconfont icon-navicon-jytj",
                //     son:[],
                //     routeName:`manageBill`,
                // }
            ],
            storeId: '', // 店铺id

            titleName: '',
            showFirstBg: false, // 
        }
    },
    methods:{
        toggleSidebar: function () {
            this.sidebarOpened = !this.sidebarOpened;
        },
        // 退出
        logOut: function () {
            localStorage.removeItem('token');
            sessionStorage.clear();
            this.$router.push('/login');
        }
    },
    created: function () {
        if ( !localStorage.getItem('first') ) {
            this.showFirstBg = true;
            localStorage.setItem('first', 'true');
        }

        if ( !sessionStorage.getItem('storeId') || !localStorage.getItem('token') || !sessionStorage.getItem('storeName') ) {
            this.$router.push('/login');
            return;
        }
        this.titleName = sessionStorage.getItem('storeName')
        this.storeId = sessionStorage.getItem('storeId');
    },
    mounted(){
        try {
            const isShowBigScreenGoods = sessionStorage.getItem("isShowBigScreenGoods");
            if(isShowBigScreenGoods == 1){
                let obj = {
                    name:"排单机",
                    iconClass: "iconfont icon-navicon-jytj",
                    son:[],
                    routeName:'bigScreenGoods',
                };
                let sidebarData = JSON.parse(JSON.stringify(this.sidebarData));
                sidebarData.splice(2,0,obj);
                this.sidebarData = sidebarData;
            }
        } catch (error) {
            console.log("error",error)
        }
    }
}
</script>
<style lang="scss" scoped>
    @import "index";
</style>
